<template>
  <a-layout class="layout" style="background: #f4f6f8">
    <!--      页头 start-->
    <a-layout-header style="padding: 0; height: 64px; line-height: 64px">
      <page-header :collapsed="collapsed" @headerToggle="toggleColl" />
    </a-layout-header>
    <a-layout style="min-height: none; height: calc(100vh - 64px)">
      <template v-if="isMobile">
        <a-drawer
          v-model:visible="collapsed"
          placement="right"
          closable
          @afterVisibleChange="collapsed = false"
        >
          <aside-menu />
        </a-drawer>
      </template>
      <template v-else>
        <a-layout-sider
          :collapsed="collapsed"
          :width="180"
          style="height: calc(100vh - 80px); overflow: auto"
          :trigger="null"
        >
          <!--      侧边菜单栏start-->
          <aside-menu />
          <!--      侧边菜单栏end-->
        </a-layout-sider>
      </template>
      <!--      页头end-->
      <!--      内容区域start-->
      <a-layout-content class="layout-content">
        <tabs-view />
        <div class="tabs-view-content">
          <router-view />
        </div>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue';
import { Layout } from 'ant-design-vue';
import TabsView from './tabs/tabs-view.vue';
import AsideMenu from './menu/menu.vue';
import PageHeader from './header/index.vue';
import PageFooter from './footer/index';
import { DEVICE_TYPE } from '@/utils/device';
import { useStore } from '@/store';

export default defineComponent({
  name: 'Layout',
  components: {
    TabsView,
    PageHeader,
    AsideMenu,
    PageFooter,
    [Layout.name]: Layout,
    [Layout.Content.name]: Layout.Content,
    [Layout.Sider.name]: Layout.Sider
  },
  setup() {
    const store = useStore();
    const isMobile = computed(() => {
      return store.state.user.device === DEVICE_TYPE.MOBILE;
    });
    const collapsed = ref<boolean>(false);
    const toggleColl = (isCollapsed) => {
      collapsed.value = isCollapsed;
    };
    return {
      collapsed,
      isMobile,
      toggleColl
    };
  }
});
</script>

<style lang="less">
.layout {
  display: flex;
  overflow: hidden;
  height: 100%;

  .ant-layout {
    overflow: hidden;
  }
}
.ant-drawer-body {
  padding: 30px 0 0 0 !important;
}
.layout-content {
  flex: none;
}
.diy-logo {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  justify-content: flex-start;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  img {
    width: 80px;
    margin-left: 30px;
  }
}
.diy-menu::-webkit-scrollbar {
  width: 0 !important;
}
.tabs-view-content {
  padding: 14px 0;
  height: calc(~'100vh - 148px');
  overflow-y: scroll;
  background: #f0f2f5;
  box-sizing: border-box;
}
</style>
